package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.Result;
import org.example.pojo.UpdatePasswordDTO;
import org.example.pojo.User;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /*
    * 查询用户信息
    * */
    @GetMapping("/userInfo")
    public Result getUserInfo(@RequestHeader("token") String token) {
        log.info("查询用户信息");
        User user = userService.getUserInfo(token);
        return Result.success(user);
    }

    /*
    * 修改密码
    * */
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) {
        log.info("修改密码");
        userService.updatePassword(updatePasswordDTO.getOldPassword(), updatePasswordDTO.getNewPassword());
        return Result.success();
    }
}
